import JSEncrypt from "jsencrypt" //存放路径

const rsaPublicKey =
  'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArjdLcCUgXKD6t90VcK8ndurGVol6exmBOjLiUCLlZYgbdQDl53XbaKPtyuX2i0ktUzjRuwYJlxEyOYimydmU50X8f/3TTSsitXhh+/QtGqHa909vTtbRLzM1T06RRG8qKBNicCOxibsNoL3WjlyYltl3wvuTETsA3DNDzR9Au3ziIfAy2zBAicdELe8RMHgp2CgIOGXwjc/DkAMy1yq2E5OPSN1Bb5IEqK6orODyvvt+RQgivfK3dciMuo4TmE3z/1PaItESSKBIp5FPNaAra7YIso9docJw51pPo2kcCmslLkd8bKqGg8oCh7NzMEGo6OWD8CnpxAHJcHoC6HQLxwIDAQAB'

//传入数据，公钥私钥
export default {

  //加密：
  // rsaEncrypt(dat, publicKey) { //需要加密的数据 rsa公钥
  // encrypt.setPublicKey(publicKey);
  rsaEncrypt(dat) { //需要加密的数据 rsa公钥
    let data;
    if (typeof dat === 'string') {
      data = dat
    } else {
      data = JSON.stringify(dat)
    }
    let encrypt = new JSEncrypt();
    encrypt.setPublicKey(rsaPublicKey);
    let encryptMsg = encrypt.encrypt(data);
    return encryptMsg;
  },

  //解密
  rsaDecrypt(data, privateKey) { //需要解密的数据， rsa私钥
    let decrypt = new JSEncrypt();
    decrypt.setPrivateKey(privateKey);
    let decryptMsg = decrypt.decrypt(data);
    return decryptMsg;
  }
}